package com.origin.ebuy.forg.web.controller.user;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSONObject;
import com.origin.ebuy.bargd.service.good.IgoodService;
import com.origin.ebuy.bargd.service.good.impl.GoodServiceImpl;
import com.origin.ebuy.forg.web.BaseServlet;

/**
 * Servlet implementation class GoodBuyServlet
 */
public class GoodBuyServlet extends BaseServlet {
	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		super.doPost(request, response);
		String  id = request.getParameter("id");
		String  number = request.getParameter("number");
		String  sf = request.getParameter("sf");
		String  city = request.getParameter("city");
		String  dtail = request.getParameter("dtail");
		String  price = request.getParameter("price");
		IgoodService service = new GoodServiceImpl();
		JSONObject object = new JSONObject();
		object.put("id", id);
		object.put("number", number);
		object.put("sf", sf);
		object.put("city", city);
		object.put("dtail", dtail);
		object.put("price", price);
		String uid = (String)request.getSession().getAttribute("uid");
		object.put("uid", uid);
		
		try {
			int i = service.buyGood(object);
			response.getWriter().print(i);
		} catch (SQLException e) {
			e.printStackTrace();
			response.getWriter().print(-1);
		}
	}

}
